package com.zy.openchat.core.model.message;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;
import java.util.List;

public class DeleteMessagesInfo implements Parcelable {
    public long chat_id;
    public List<Long> message_ids;
    private boolean is_permanent;
    private boolean from_cache;

    public long getDeleteMessageId(){
        if(message_ids!=null&&message_ids.size()>0){
            return message_ids.get(0);
        }else{
            return -1;
        }
    }

    public boolean isRealDelete() {
        return is_permanent && !from_cache;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.chat_id);
        dest.writeList(this.message_ids);
        dest.writeByte(this.is_permanent ? (byte) 1 : (byte) 0);
        dest.writeByte(this.from_cache ? (byte) 1 : (byte) 0);
    }

    public DeleteMessagesInfo() {
    }

    protected DeleteMessagesInfo(Parcel in) {
        this.chat_id = in.readLong();
        this.message_ids = new ArrayList<Long>();
        in.readList(this.message_ids, Long.class.getClassLoader());
        this.is_permanent = in.readByte() != 0;
        this.from_cache = in.readByte() != 0;
    }

    public static final Creator<DeleteMessagesInfo> CREATOR = new Creator<DeleteMessagesInfo>() {
        @Override
        public DeleteMessagesInfo createFromParcel(Parcel source) {
            return new DeleteMessagesInfo(source);
        }

        @Override
        public DeleteMessagesInfo[] newArray(int size) {
            return new DeleteMessagesInfo[size];
        }
    };
}
